<template>
  <el-card class="fontAuth">
    <h1>后台权限示例</h1>
    <CurrentPermissionMode />
  </el-card>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue'
import CurrentPermissionMode from '../CurrentPermissionMode.vue'
// 使用该方法导入useStore可以加入ts提示
import { useStore } from '@/store'
import { RoleEnum } from '@/enums/roleEnum'

export default defineComponent({
  components: {
    CurrentPermissionMode
  },
  setup() {
    const store = useStore()

    const roleList = computed(() => store.state.login.roleList)

    function changeRole(role) {
      store.commit('login/setRoleList', [role])
      location.reload()
    }

    return {
      roleList,
      isSuper: computed(() => store.state.login.roleList.includes(RoleEnum.SUPER)),
      isTest: computed(() => store.state.login.roleList.includes(RoleEnum.TEST)),
      changeRole,
      RoleEnum
    }
  }
})
</script>

<style lang="scss" scoped>
.fontAuth {
  height: 200%;
  font-size: 16px;

  h1 {
    font-size: 24px;
    padding: 10px 0;
  }
}
</style>
